package com.example.lenovo.mywechat.homepage.wechat;

import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.lenovo.mywechat.R;
import com.example.lenovo.mywechat.temp.chat_page.ChatPageActivity;

import java.util.List;

public class SessionAdapter extends RecyclerView.Adapter {
    List<Session> sessions;
    Activity mActivity;

    public SessionAdapter(List<Session> sessions, Activity mActivity) {
        this.sessions = sessions;
        this.mActivity = mActivity;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        //此方法是将一条会话布局返回。
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.wechat_content_item,
                viewGroup, false);
        return new RecyclerView.ViewHolder(view){};//RecyclerView.ViewHolder是一个抽象类，这里使用匿名类。
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        //此方法是为了显示什么数据、如何显示布局

        ImageView icon = viewHolder.itemView.findViewById(R.id.iv_icon);
        TextView title = viewHolder.itemView.findViewById(R.id.tv_title);
        TextView briefIntroduction = viewHolder.itemView.findViewById(R.id.tv_brief_introduction);
        TextView time = viewHolder.itemView.findViewById(R.id.tv_time);
        RelativeLayout relativeLayout = viewHolder.itemView.findViewById(R.id.rl_session);

        icon.setImageResource(sessions.get(i).icon);
        title.setText(sessions.get(i).title);
        briefIntroduction.setText(sessions.get(i).briefIntroduction);
        time.setText(sessions.get(i).time);
//        relativeLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(mActivity, ChatPageActivity.class);
//                mActivity.startActivity(intent);
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return sessions.size();
    }
}
